package com.zzyl.nursing.controller.mumber;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.member.Reservation;
import com.zzyl.nursing.dto.member.ReservationDTO;
import com.zzyl.nursing.service.member.IMemberReservationService;
import com.zzyl.nursing.vo.member.TimeCountVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 参观预约控制层
 *
 * @author makangkang
 * @date 2025/10/22 22:10
 */
@RestController
@RequestMapping("/member/reservation")
public class MemberReservationController extends BaseController {

    @Autowired
    private IMemberReservationService memberReservationService;

    /**
     * 查询当天取消预约数量
     * @return
     */
    @GetMapping("/cancelled-count")
   public AjaxResult cancelledCount() {
        return success(memberReservationService.cancelledCount());
    }

    /**
     * 查询每个时间段剩余预约次数
     * @return
     */
    @GetMapping("/countByTime")
    public R<List<TimeCountVO>> countByTime(Long time) {
        List<TimeCountVO> timeCountVO = memberReservationService.countByTime(time);
        return R.ok(timeCountVO);
    }


    /**
     * 新增预约
     * @return
     */
    @PostMapping
    public AjaxResult addReservation(@RequestBody ReservationDTO reservationDTO) {
        return toAjax(memberReservationService.addReservation(reservationDTO));
    }

    /**
     * 分页查询预约
     * @return
     */
    @GetMapping("/page")
    public AjaxResult reservationPage(Reservation reservation) {
        startPage();
        List<Reservation> reservationList = memberReservationService.reservationPage(reservation);
        return AjaxResult.success(getDataTable(reservationList));
    }

    /**
     * 取消预约
     * @return
     */
    @PutMapping("/{id}/cancel")
    public AjaxResult cancelById(@PathVariable Long id) {
        return toAjax(memberReservationService.cancelById(id));
    }
}
